package com.yincheng.oms.sso.service;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yincheng.oms.sso.entity.User;
import com.yincheng.oms.sso.mapper.UserMapper;

@Service
public class UserService {

	@Autowired
	private UserMapper userMapper;
	
//	@Autowired
//	private UserRoleMapper userRoleMapper;
	
	/**
	 * 保存用户信息，如果已存在则更新用户信息
	 * @param user
	 */
	public void saveUser(User user) {
		int key = userMapper.update(user);
		if(key == 0) {
			user.setCreateTime(new Date());
			user.setValid("1");//默认激活
			userMapper.insert(user);
		}
	}
	
	/**
	 * 根据账号获取用户信息
	 * @param userAccount
	 * @return
	 */
	public User getUserByUserAccount(String userAccount) {
		User user = userMapper.selectByUserAccount(userAccount);
		return user;
	}
}
